package com.bdy.lm.taximanager.ui;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.bdy.lm.taximanager.R;
import com.bdy.lm.taximanager.app.MyApp;
import com.bdy.lm.taximanager.port.TaxiMeterDataAnalysis;
import com.bdy.lm.taximanager.util.serial;

public class SerialActivity extends AppCompatActivity implements TaxiMeterDataAnalysis.LocalQueryParameter{

    private TextView fareFrom, priceDayDown, priceNightDown, waitPrice, priceDay, priceNight, nightFrom, nightEnd, taximeterTime, kValue;
    private Handler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_serial);

        fareFrom = (TextView) findViewById(R.id.fare_from);
        priceDayDown = (TextView) findViewById(R.id.price_day_down);
        priceNightDown = (TextView) findViewById(R.id.price_night_down);
        waitPrice = (TextView) findViewById(R.id.wait_price);
        priceDay = (TextView) findViewById(R.id.price_day);
        priceNight = (TextView) findViewById(R.id.price_night);
        nightFrom = (TextView) findViewById(R.id.night_from);
        nightEnd = (TextView) findViewById(R.id.night_end);
        taximeterTime = (TextView) findViewById(R.id.taximeter_time);
        kValue = (TextView) findViewById(R.id.k_value);

        TaxiMeterDataAnalysis.newInstance().setLocalQueryParameter(this);
        TaxiMeterDataAnalysis.newInstance().getTaximeterParameter(TaxiMeterDataAnalysis.LOCAL);
        System.out.println("SerialActivity 已查询");
        handler = new Handler() {
            public void handleMessage(Message msg) {
                if (msg.what == 101) {
                    System.out.println("SerialActivity" + TaxiMeterDataAnalysis.queryParameter);
                    fareFrom.setText(TaxiMeterDataAnalysis.queryParameter.getFareFrom());
                    priceDayDown.setText(TaxiMeterDataAnalysis.queryParameter.getFareDayDown());
                    priceNightDown.setText(TaxiMeterDataAnalysis.queryParameter.getFareNightDown());
                    waitPrice.setText(TaxiMeterDataAnalysis.queryParameter.getFareWait());
                    priceDay.setText(TaxiMeterDataAnalysis.queryParameter.getPriceDay());
                    priceNight.setText(TaxiMeterDataAnalysis.queryParameter.getPriceNight());
                    nightFrom.setText(TaxiMeterDataAnalysis.queryParameter.getNigthFrom());
                    nightEnd.setText(TaxiMeterDataAnalysis.queryParameter.getNightEnd());
                    taximeterTime.setText(TaxiMeterDataAnalysis.taximeterTime);
                    kValue.setText(TaxiMeterDataAnalysis.queryParameter.getK());
                }
            }
        };
    }
    @Override
    public void passParameter() {
        System.out.println("SerialActivity 已回调");
        handler.sendEmptyMessage(101);
    }
}
